package chen.web.controller.forum;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.json.JSONException;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import chen.web.util.OperationSystemInfoProvider;
import chen.web.util.OperationSystemInfoProvider.OperationSystemInfo;

@Controller
public class SystemInfoController {

	@RequestMapping(value="/systemInfo", method=RequestMethod.GET)
	public @ResponseBody JSONResponse systemInfo(@RequestParam long timestamp) throws JSONException{
		//checkPermisstion();
		ArrayList<Map<String, Object>> array = new ArrayList<Map<String, Object>>();
		OperationSystemInfoProvider.setPeriod(2000);
		List<OperationSystemInfo> infoList = OperationSystemInfoProvider.getOperationSystemInfoList(timestamp);
		for(OperationSystemInfo info : infoList){
			Map<String, Object> map = new HashMap<String, Object>();
			map.put("timestamp", String.valueOf(info.getTimestamp()));
			map.put("totalPhysicalMemorySize", String.valueOf(info.getTotalPhysicalMemorySize()));
			map.put("freePhysicalMemorySize", String.valueOf(info.getFreePhysicalMemorySize()));
			map.put("cpuUsedPercent", info.getCpuUsedPercent());
			map.put("cpuWaitPercent", info.getCpuWaitPercent());
			array.add(map);
		}
		return JSONResponse.successed(array);	
	}
	
}
